package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity13 extends AppCompatActivity {
    //private ImageView img_avatar;
    private Button btn_avatar,button1,button2;
    TextView one,two,three;
    EditText a,b,c;
    ImageView img;
    int[] imgs = new int[]{
            R.drawable.touxiang1,
            R.drawable.touxiang2
    };
    int i=0,j=0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main13);
        initView();
        btn_avatar();
        btn_Submit_form();
        btn_look();
    }
    private void initView() {
        one=findViewById(R.id.textView2);
        two=findViewById(R.id.textView3);
        three=findViewById(R.id.textView4);

        a=findViewById(R.id.editText2);
        b=findViewById(R.id.editText);
        c=findViewById(R.id.editText3);

        img=findViewById(R.id.imageView_avatar);
        btn_avatar=findViewById(R.id.button_avatar);
        button1=findViewById(R.id.button_submitform);
        button2=findViewById(R.id.button_look);
        //img_avatar=(ImageView) findViewById(R.id.imageView_avatar);
    }
    //更换头像
    private void btn_avatar() {
        btn_avatar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                i++;
                i=i%2;
                switch (i)
                {
                    case 0: img.setBackgroundResource(imgs[i]);j=i;break;
                    case 1: img.setBackgroundResource(imgs[i]);j=i;break;
                }
            }
        });
    }
    //信息提交
    private void btn_Submit_form() {
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //switch ()
                Intent intent = new Intent();
                String value1,value2,value3;
                value1=a.getText().toString().trim();
                value2=b.getText().toString().trim();
                value3=c.getText().toString().trim();
                intent.putExtra("name",a.getText().toString().trim());
                intent.putExtra("pwd",b.getText().toString().trim());
                intent.putExtra("school",c.getText().toString().trim());
                intent.putExtra("image",j);
                intent.setClass(MainActivity13.this,MainActivity.class);
                startActivity(intent);
            }
        });
    }
    //信息查看
    private void btn_look() {
        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1 = new Intent();
                String value1,value2,value3;
                value1=a.getText().toString().trim();
                value2=b.getText().toString().trim();
                value3=c.getText().toString().trim();
                intent1.putExtra("name",a.getText().toString().trim());
                intent1.putExtra("pwd",b.getText().toString().trim());
                intent1.putExtra("school",c.getText().toString().trim());
                intent1.putExtra("image",j);
                intent1.setClass(MainActivity13.this,MainActivity14.class);
                startActivity(intent1);
            }
        });
    }
}